package com.example.timmy.myapplication.ui.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;

import com.example.timmy.myapplication.R;
import com.example.timmy.myapplication.presenter.AndroidChatActivityPresenter;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.ChartTouchListener;
import com.github.mikephil.charting.listener.OnChartGestureListener;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;

/**
 * MPAndroidChat 示例图
 */
public class AndroidChatActivity extends AppCompatActivity {


    private static final String TAG = AndroidChatActivity.class.getSimpleName();

    private LineChart mChart;
    private AndroidChatActivityPresenter mActivityPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_android_chat);

        initChart();
    }

    @Override
    protected void onStart() {
        super.onStart();
        // initData();

        mActivityPresenter = new AndroidChatActivityPresenter(this);
        mActivityPresenter.initData(mChart);
    }

    private void initChart() {
        mChart = (LineChart) findViewById(R.id.chart1);
        // 设置手势滑动事件
        mChart.setOnChartGestureListener(mOnChartGestureListener);
        // 设置数值选择监听
        mChart.setOnChartValueSelectedListener(mOnChartValueSelectedListener);
        // 后台绘制
        mChart.setDrawGridBackground(false);
        // 设置描述文本
        mChart.getDescription().setEnabled(false);
        // 设置支持触控手势
        mChart.setTouchEnabled(true);
        mChart.setDragDecelerationFrictionCoef(0.9f);

        // 支持缩放和拖动
        mChart.setDragEnabled(true);
        mChart.setScaleEnabled(true);
        mChart.setDrawGridBackground(false);
        mChart.setHighlightPerDragEnabled(true);
        mChart.setDoubleTapToZoomEnabled(false);

        // 如果禁用,扩展可以在 Z 轴和 Y 轴分别完成
        mChart.setPinchZoom(true);

        Legend legend = mChart.getLegend();
        legend.setEnabled(false);

        // 设置背景颜色(灰色)
        // mChart.setBackgroundColor(Color.BLACK);
    }


    // ========================== Listener Start =================================
    private OnChartGestureListener mOnChartGestureListener = new OnChartGestureListener() {
        @Override
        public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
            Log.i(TAG, "onChartGestureStart");
        }

        @Override
        public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
            Log.i(TAG, "onChartGestureEnd");
        }

        @Override
        public void onChartLongPressed(MotionEvent me) {
            Log.i(TAG, "onChartLongPressed");
        }

        @Override
        public void onChartDoubleTapped(MotionEvent me) {
            Log.i(TAG, "onChartDoubleTapped");
        }

        @Override
        public void onChartSingleTapped(MotionEvent me) {
            Log.i(TAG, "onChartSingleTapped");
        }

        @Override
        public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
            Log.i(TAG, "onChartFling");
        }

        @Override
        public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
            Log.i(TAG, "onChartScale");
        }

        @Override
        public void onChartTranslate(MotionEvent me, float dX, float dY) {
            Log.i(TAG, "onChartTranslate");
        }
    };

    private OnChartValueSelectedListener mOnChartValueSelectedListener = new OnChartValueSelectedListener() {
        @Override
        public void onValueSelected(Entry e, Highlight h) {
            Log.i(TAG, "onValueSelected");
        }

        @Override
        public void onNothingSelected() {
            Log.i(TAG, "onNothingSelected");

        }
    };

    // ========================== Listener End =================================
}
